I got tricked
Part one asks you to implement a simulation, part two is a simulation too big to simulate, again.
For this part 2, it is not enough to simply run the simulation for information, you have to start analyzing your input file. I haven't confirmed that this is the same for everyone, but I'd be surprised if it wasn't:
The last module before
rx
is a conjunction with four inputs.
So in order for rx
to receive a low pulse, that conjunction module needs to receive four high pulses. With this information in hand, we should be able to run the simulation and find the intervals for each of those four inputs, then combine them.
So, with my trusty press_button
from part one, I wrote, roughly:
for step in 1.. {
press_button(&mut modules);
if modules[last_conjunction].state > 0 {
// record the step this happened
}
}
So, every time the last conjunction ends with any remembered high state, it would print something and remember that number.
Except, the condition never triggered.
Figuring this approach wouldn't work, I then spent a solid chunk of time following down other leads—at one point I was halfway towards reverse-engineering the intervals during which each module is active and so on.
But turns out, I overlooked one simple fact: The conjunction is sent a low at some point after each high. So no matter what actually happens during the button press, at the end, the remembered state is all lows.
You need to actually intercept the signals being sent themselves, rather than relying on the state
after everything is resolved.
Once I realized that, it once again became a simple matter of finding the intervals and LCMing them together.